// pages/home/home.js
import {
  showText
} from "../../utils/util"
import {
  getshopinfo
} from '@/api/spa'
import {
  getgemomemberuser
} from '@/api/my'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    imgUri: getApp().globalData.imgUri,
    show:false,
    radio:0,
    brand:'', // 门店
    absId:0,
    spaId:0,
    bookingId:0,
    porpParams:{},
    phone:'',
    realname:'',
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    let t = this;
    if(options.absId){
      let absId = options.absId;
      let spaId = options.spaId;
      let bookingId = options.bookingId;
      getgemomemberuser({absId:absId}).then(res=>{
        if(res.code == 200){
          let data = res.data;
          let radio = 0;
          if(data.gender == "女"){
            radio = 2;
          }else if(data.gender == "男"){
            radio = 1;
          }
          let realname = "";
          if(data.familyName){
            realname = data.familyName+data.givenName;
          }
          t.setData({
            porpParams:{mobile:data.phonenumber},
            phone:data.phonenumber,
            realname:realname,
            radio:radio,
            bookingId:bookingId,
            absId:absId,
            spaId:spaId,
          });
          t.f_getshopinfo();


        }
      });
      var phone = wx.getStorageSync('phone');
      t.setData({
        porpParams:{mobile:phone},
      })
    }
  },
  f_getshopinfo(){
    let t = this;
    getshopinfo({absId:t.data.absId}).then(res=>{
      if(res.code == 200){
        var phone = wx.getStorageSync('phone');
        t.setData({
          brand:res.data.shopName,
        });
      }
    });
  },
  radiosel(e) {
    console.log()
    this.setData({
      radio: e.currentTarget.dataset.nums
    })
  },
  bindbrandChange(e){
    let { value } = e.detail
    this.setData({
      brand: this.data.brandArray[value].name
    })
  },
  // 表单提交
  formSubmit(e){
    let { name,phone,brand } = e.detail.value
    if(!name){
      showText('请输入姓名')
      return
    }
    if(!phone){
      showText('请输入联系方式')
      return
    }
    if(this.data.radio == 0){
      showText('请选择称谓')
      return
    }

    let gender = '';
    if(this.data.radio == 1){
      gender = '男';
    }else{
      gender = '女';
    }

    let params = {
      shopId: parseInt(this.data.absId),
      spaId: parseInt(this.data.spaId),
      mobile: phone,
      name: name,
      gender:this.data.radio,
      brand:this.data.brand,
      bookingId:this.data.bookingId,
    }
    this.setData({
      params,
      show:true
    })
  },
  closeProp5(){
    this.setData({
      show:false
    })
  },
  successProp5(params){
    this.setData({
      show:false
    },()=>{
      wx.redirectTo({
        url: '/pages/bookSuccess/bookSuccess?params='+this.data.porpParams,
      })
    })
  },
  onShareAppMessage() {
    return {
      title: getApp().globalData.share_title,
      path: getApp().globalData.share_url,
      imageUrl: getApp().globalData.share_image,
    }
  }
})